package com.yztc.yidoutang.activity.daren_activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;

import com.yztc.yidoutang.R;
import com.yztc.yidoutang.activity.darenshow_activity.DaRenShowActivity;
import com.yztc.yidoutang.adapter.DaRenAdapter;
import com.yztc.yidoutang.base.BaseActivity;
import com.yztc.yidoutang.bean.DaRenListBean;

import java.util.List;

/**
 * Created by My on 2016/10/19.
 */

public class DaRenActivity extends BaseActivity implements DaRenContract.View {
    private SwipeRefreshLayout swipeRefreshLayout;
    private ListView lv;
    private DaRenAdapter adapter;
    private DaRenPresenter presenter=new DaRenPresenter(this);
    private Intent intent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        refresh();
    }
    @Override
    public int getLayoutId() {
        return R.layout.activity_daren;
    }
    private void refresh() {
        //设置刷新时动画的颜色
        swipeRefreshLayout.setColorSchemeResources(R.color.clr_orange);
        //刷新的监听事件
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        presenter.getDataForNet();
                        swipeRefreshLayout.setRefreshing(false);
                    }
                },2000);
            }
        });
    }

    private void initView() {
        lv= (ListView) findViewById(R.id.dr_lv);
        //給ListView添加头部
        lv.addHeaderView(LayoutInflater.from(this).inflate(R.layout.item_daren_radiogroup,null));
        //給ListView添加尾部
        lv.addFooterView(LayoutInflater.from(this).inflate(R.layout.item_jingxuanfoot,null));
        swipeRefreshLayout= (SwipeRefreshLayout) findViewById(R.id.dr_swipe_layout);
        presenter.getDataForNet();
    }

    @Override
    public void onDaRenSuccess(List<DaRenListBean> daRenListBeanList) {
        adapter=new DaRenAdapter(this,daRenListBeanList);
        lv.setAdapter(adapter);
    }

    @Override
    public void onDaRenFail(String msg) {

    }
    //上方五个按钮的点击事件
    public void onClick(View view){
        switch (view.getId()){
            case R.id.dr_btn_gouwu:
                intent=new Intent(this,DaRenShowActivity.class);
                intent.putExtra("type",90+"");
                startActivity(intent);
                break;
            case R.id.dr_btn_jiazhuang:
                intent=new Intent(this,DaRenShowActivity.class);
                intent.putExtra("type",91+"");
                startActivity(intent);
                break;
            case R.id.dr_btn_dapei:
                intent=new Intent(this,DaRenShowActivity.class);
                intent.putExtra("type",92+"");
                startActivity(intent);
                break;
            case R.id.dr_btn_jujia:
                intent=new Intent(this,DaRenShowActivity.class);
                intent.putExtra("type",93+"");
                startActivity(intent);
                break;
            case R.id.dr_btn_fengshui:
                intent=new Intent(this,DaRenShowActivity.class);
                intent.putExtra("type",94+"");
                startActivity(intent);
                break;
            case R.id.dr_btn_back:
                finish();
                break;
        }
    }


}
